<!--
 * @Description: icon 组件
 * @Autor: codeBo
 * @Date: 2023-05-15 15:37:52
 * @LastEditors: gjzxlihaibo@163.com
 * @LastEditTime: 2023-05-16 16:21:36
-->
<template>
  <el-icon>
    <el-image v-if="!isImg" :src="url" fit="cover" />
    <component v-else :is="url"></component>
  </el-icon>
</template>
<script lang="ts">
import { computed, defineComponent } from 'vue'

export default defineComponent({
  props: {
    url: {
      type: String,
      required: true,
    },
  },
  /**
   *
   * @param props  url 传入的icon 可以是 http 地址 可以是本地地址
   *
   */
  setup(props) {
    const pathRegex = /^(https?:\/\/)?([\w.-]+)(\/[^\s]*)?$/i
    const isImg = computed(() => pathRegex.test(props.url))
    return {
      isImg,
    }
  },
})
</script>
<style lang="scss" scoped></style>
